package com.cucn.mms.common.common;

import com.cucn.mms.common.enums.ResultEnum;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class R<T> {
    public static final String ROWS = "rows";
    public static final String TOTAL = "total";
    public static final String RESULT = "result";
    private final Map<String,Object> map = new HashMap<>();

    public void setRows(List<T> list){
        this.map.put(ROWS,list);
    }

    public void setTotal(int total){
        this.map.put(TOTAL,total);
    }

    public void setResult(ResultEnum type){
        this.map.put(RESULT,type.getType());
    }

    public static <T> Map<String,Object> success(List<T> rows,int total){
        R<T> r = new R<>();
        r.setRows(rows);
        r.setTotal(total);
        r.setResult(ResultEnum.SUCCESS);
        return r.map;
    }

    public static <T> Map<String,Object> success(){
        R<T> r = new R<>();
        r.setResult(ResultEnum.SUCCESS);
        return r.map;
    }

    public static <T> Map<String,Object> error(){
        R<T> r = new R<>();
        r.setResult(ResultEnum.ERROR);
        return r.map;
    }
}
